package com.deer.wms.busine.tactic.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.deer.wms.busine.tactic.dao.PrintTempInfoMapper;
import com.deer.wms.busine.tactic.model.PrintTempInfo;
import com.deer.wms.busine.tactic.model.PrintTempInfoCriteria;
import com.deer.wms.busine.tactic.service.PrintTempInfoService;
import com.deer.wms.project.root.util.BarCodeUtils;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by  on 2020/11/13.
 */
@Service
@Transactional
public class PrintTempInfoServiceImpl extends ServiceImpl<PrintTempInfoMapper, PrintTempInfo> implements PrintTempInfoService {

    @Autowired
    private PrintTempInfoMapper printTempInfoMapper;

    @Override
    public void setTempData(String eleId, Object data, Document doc, String type) {
        if (data==null){
            return;
        }
        if(doc.getElementById(eleId)!=null){
            List<Element> aaa= doc.getElementsByAttributeValue("id",eleId);
            for (Element ele:aaa
            ) {
                switch (type){
                    case "text":
                        ele.text(data.toString());
                        break;
                    case "qrCode":
                        ele.getElementsByTag("img").attr("src", BarCodeUtils.encode(data.toString(),300,300));
                        break;
                    case "barCode":
                        ele.getElementsByTag("img").attr("src", BarCodeUtils.encodeTiaoXingMa(data.toString(),400,50));
                        break;
                }
            }
        }
    }

    public PrintTempInfo findByWare(Integer wareId,String type){
       return  printTempInfoMapper.findByWare(wareId,type);
    }

    @Override
    public PrintTempInfo findByWareAndShip(Integer wareId, String shipCode) {
        return  printTempInfoMapper.findByWareAndShip(wareId,shipCode);
    }

    @Override
    public List<PrintTempInfo> findList(PrintTempInfoCriteria criteria) {
        return  printTempInfoMapper.findList(criteria);
    }
}
